import React from 'react';
import {connect} from 'dva/index';
import {Cascader} from 'antd';

const R = require('ramda');


class AreaSelect extends React.Component {
    constructor(props) {
        super(props);
        this.state = { areaTree: [] }
    }
    componentDidMount() {
		if (this.state.areaTree.length === 0) {
			this.props.dispatch({
				type: 'app/getAreaTree',
				onSuccess: (data) => {
					this.setState({ areaTree: data });
				}
			});
		}
    }

    render () {
        return (
            <Cascader
                showSearch
                disabled={this.state.areaTree.length === 0}
                options={this.state.areaTree}
                {...R.omit(['app', 'dispatch'])(this.props)}
                placeholder="请选择地区"
            />
        );
    }
}

export default connect(({app}) => ({app}))(AreaSelect)